package titt.io.reader.head;

import titt.head.HTTPHead;

public class PushbackHeadReader implements HeadReader {
	
	private final HeadReader hr;

	private HTTPHead h = null;
	
	public PushbackHeadReader(HeadReader hr) {
		this.hr = hr;
	}
	
	@Override
	public HTTPHead readHead() throws Exception {
		if(h != null) {
			HTTPHead tmp = h;
			h = null;
			return tmp;
		}
		return hr.readHead();
	}

	@Override
	public HTTPHead readHead(boolean waitForStatus) throws Exception {
		if(h != null) {
			HTTPHead tmp = h;
			h = null;
			return tmp;
		}
		return hr.readHead(waitForStatus);
	}
	
	public void unreadHead(HTTPHead head) {
		h = head;
	}
	

}
